//package com.gpframework.module.controller.order;
//
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//
//import java.util.ArrayList;
//import java.util.Iterator;
//import java.util.List;
//import java.util.Arrays;
//import cn.hutool.core.convert.Convert;
//import cn.hutool.core.lang.TypeReference;
//import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
//import com.gpframework.common.enums.YesNoEnum;
//import com.gpframework.common.exception.ParamException;
//import com.gpframework.common.utils.StringUtils;
//import com.gpframework.module.order.domain.GpForwardLogDetail;
//import com.gpframework.module.order.domain.GpOrder;
//import com.gpframework.module.order.domain.req.GpForwardLogDetailAdd;
//import com.gpframework.module.order.service.IGpForwardLogDetailService;
//import com.gpframework.module.order.service.IGpOrderService;
//import lombok.RequiredArgsConstructor;
//import org.apache.commons.collections4.CollectionUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.transaction.annotation.Transactional;
//import org.springframework.validation.annotation.Validated;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.PostMapping;
//import org.springframework.web.bind.annotation.PutMapping;
//import org.springframework.web.bind.annotation.DeleteMapping;
//import org.springframework.web.bind.annotation.PathVariable;
//import org.springframework.web.bind.annotation.RequestBody;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//import com.gpframework.common.annotation.Log;
//import com.gpframework.common.core.controller.BaseController;
//import com.gpframework.common.core.domain.AjaxResult;
//import com.gpframework.common.enums.BusinessType;
//import com.gpframework.module.order.domain.GpForwardLog;
//import com.gpframework.module.order.domain.vo.GpForwardLogVo;
//import com.gpframework.module.order.domain.req.GpForwardLogReq;
//import com.gpframework.module.order.domain.req.GpForwardLogAdd;
//import com.gpframework.module.order.domain.req.GpForwardLogUpdate;
//import com.gpframework.module.order.service.IGpForwardLogService;
//import com.gpframework.common.utils.poi.ExcelUtil;
//import javax.validation.Valid;
//import io.swagger.annotations.*;
//import com.gpframework.common.core.page.TableDataInfo;
///**
// * @ClassName GpForwardLogController
// * @Author gpframework
// * @Date 2023-08-29
// * @Version 1.0.0
// * @Description 转发记录Controller 接口类
// */
//@Validated
//@Api(tags = "转发记录")
//@RequiredArgsConstructor(onConstructor_ = @Autowired)
//@RestController
//@RequestMapping("/order/forwardLog" )
//public class GpForwardLogController extends BaseController {
//
//    private final IGpForwardLogService iGpForwardLogService;
//    private final IGpForwardLogDetailService iGpForwardLogDetailService;
//    private final IGpOrderService iGpOrderService;
//
// /**
//  * @Description 分页
//  * @Author gpframework
//  * @Date 2023-08-29
//  * @Param gpForwardLog
//  * @Return TableDataInfo
// */
//    @ApiOperation("列表")
//    @GetMapping("/list")
//    public TableDataInfo<GpForwardLogVo> list(GpForwardLogReq gpForwardLogReq)
//    {
//        startPage();
//        QueryWrapper<GpForwardLog> lqw = new QueryWrapper<GpForwardLog>();
//        gpForwardLogReq.generatorQuery(lqw,true);
//        List<GpForwardLogVo> list = iGpForwardLogService.listVo(lqw);
//        return getDataTable(list);
//    }
//
//    /**
//     * @Description 详情
//     * @Author gpframework
//     * @Date 2023-08-29
//     * @Param gpForwardLog
//     * @Return AjaxResult
//     */
//    @ApiOperation("详情")
//    @GetMapping(value = "/{id}" )
//    public AjaxResult<GpForwardLogVo> getInfo(@PathVariable("id" ) Long id) {
//        return AjaxResult.success(iGpForwardLogService.getVoById(id));
//    }
//
//    /**
//     * @Description 新增
//     * @Author gpframework
//     * @Date 2023-08-29
//     * @Param gpForwardLog
//     * @Return AjaxResult
//     */
//    @ApiOperation("新增")
//    @PostMapping
//    @Transactional
//    public AjaxResult add(@Valid @RequestBody GpForwardLogAdd gpForwardLogAdd) {
//        if (CollectionUtils.isEmpty(gpForwardLogAdd.getForwardLogDetailAddList())) {
//            return AjaxResult.error("请至少选择一个订单进行转发");
//        }
//        GpForwardLog gpForwardLog = Convert.convert(new TypeReference<GpForwardLog>() {}, gpForwardLogAdd);
//        boolean save = iGpForwardLogService.save(gpForwardLog);
//        if (save) {
//            List<GpForwardLogDetail> forwardLogDetailList = new ArrayList<>();
//            GpForwardLogDetail gpForwardLogDetail;
//            for (GpForwardLogDetailAdd gpForwardLogDetailAdd : gpForwardLogAdd.getForwardLogDetailAddList()) {
//                gpForwardLogDetail = Convert.convert(new TypeReference<GpForwardLogDetail>() {}, gpForwardLogDetailAdd);
//                gpForwardLogDetail.setForwardLogId(gpForwardLog.getId());
//                gpForwardLogDetail.setAnnex(String.join(",", gpForwardLogDetailAdd.getAnnexList()));
//                // 更新转发状态
//                GpOrder order = iGpOrderService.getById(gpForwardLogDetail.getOrderId());
//                if (order == null) {
//                    continue;
//                }
//                if (gpForwardLogAdd.getIsForwardImg() != null && gpForwardLogAdd.getIsForwardImg() == 1) {
//                    order.setIsForwardImg(1);
//                }
//                if (gpForwardLogAdd.getIsForwardVideo() != null && gpForwardLogAdd.getIsForwardVideo() == 1) {
//                    order.setIsForwardVideo(1);
//                }
//                if ((order.getIsForwardImg() == 1 && order.getIsForwardVideo() == 1) || (gpForwardLogAdd.getIsForward() != null && gpForwardLogAdd.getIsForward() == 1)) {
//                    order.setIsForward(1);
//                }
//                iGpOrderService.updateById(order);
//                forwardLogDetailList.add(gpForwardLogDetail);
//            }
//            iGpForwardLogDetailService.saveBatch(forwardLogDetailList);
//        }
//        if (save) {
//            return AjaxResult.success(gpForwardLog);
//        } else {
//            return AjaxResult.error("发送失败，请联系管理员");
//        }
//    }
//
//    /**
//     * @Description 修改
//     * @Author gpframework
//     * @Date 2023-08-29
//     * @Param gpForwardLog
//     * @Return AjaxResult
//     */
//    @ApiOperation("修改")
//    @PutMapping
//    public AjaxResult edit(@Valid @RequestBody GpForwardLogUpdate gpForwardLogUpdate) {
//        GpForwardLog gpForwardLog = Convert.convert(new TypeReference<GpForwardLog>() {}, gpForwardLogUpdate);
//        return toAjax(iGpForwardLogService.updateById(gpForwardLog) ? 1 : 0);
//    }
//
//    /**
//     * @Description 删除
//     * @Author gpframework
//     * @Date 2023-08-29
//     * @Param gpForwardLog
//     * @Return AjaxResult
//     */
//    @ApiOperation("删除")
//    @DeleteMapping("/{ids}" )
//    public AjaxResult remove(@PathVariable Long[] ids) {
//        return toAjax(iGpForwardLogService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
//    }
//}
